/**
 * 
 */
package org.vsg.common.orm.hibernate;

import java.io.Serializable;

import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 * @author vison
 *
 */
public abstract class AbstractGenericDaoImpl implements GenericDao {
	
	/**
	 * set the logger for develope code , do not use System.print(ln) to out print message.
	 */
	protected static final Logger logger = LoggerFactory.getLogger(AbstractGenericDaoImpl.class);	
	
	private HibernateTemplate template;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.template = new HibernateTemplate(sessionFactory);
	}
	
	/**
	 * get the defined template
	 * @return
	 */
	public HibernateTemplate getTemplate() {
		return template;
	}

	/* (non-Javadoc)
	 * @see org.vsg.common.hibernate.GenericDao#delete(java.lang.Object)
	 */
	@Override
	public void delete(Object entity) throws DataAccessException {
		// TODO Auto-generated method stub
		template.delete(entity);
	}

	/* (non-Javadoc)
	 * @see org.vsg.common.hibernate.GenericDao#load(java.io.Serializable)
	 */
	@Override
	public Object load(Class cls , Serializable pk) throws DataAccessException {
		// TODO Auto-generated method stub
		return template.load( cls , pk);
	}

	/* (non-Javadoc)
	 * @see org.vsg.common.hibernate.GenericDao#save(java.lang.Object)
	 */
	@Override
	public void save(Object entity) throws DataAccessException {
		// TODO Auto-generated method stub
		template.save( entity );
	}

	/* (non-Javadoc)
	 * @see org.vsg.common.hibernate.GenericDao#update(java.lang.Object)
	 */
	@Override
	public void update(Object entity) throws DataAccessException {
		// TODO Auto-generated method stub
		template.update(entity);
	}

}
